<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class Category extends Model
{
    //获取产品类型信息
    public function categoryInfo(){
        echo  1111;
        //获取产品类型信息
        return DB::select('select * from fs_categorys ');
    }
    
    
    
    //保存产品类型信息
    public function saveCategory($data){

        //判断产品类型ID是否为空
        if(empty($data['id'])){

            foreach ($data as $k => $v){
                if($k == '_token'){
                    unset($data['_token']);
                }
            }

            //添加产品类型信息
            $result = DB::table('categorys')->insert($data);
            if($result === false){
                $result = ['code' => 1, 'info' => '添加失败!'];
            }else{
                $result = ['code' => 0, 'info' => '添加成功!'];
            }

            return $result;
        }
    }
}
